<script>
/**
 * @desc 社区页面
 */

import { mapState, mapActions } from 'vuex'
import { navTo } from '@/utils'
import ArticleSwiper from './article-swiper'
import cameraIco from '@/assets/icons/camera.png'

export default {
  name: 'community-page',
  components: { ArticleSwiper },
  data: () => ({
    cameraIco
  }),
  computed: { ...mapState('SignIn', ['isLogin']) },
  methods: {
    ...mapActions('Community', ['getPosts']),

    handleClick() {
      if (this.isLogin) {
        wx.chooseImage({
          count: 1,
          success: res => {
            navTo({ name: 'publish-post', query: { img: res.tempFilePaths[0] } })
          }
        })
      } else {
        wx.showModal({ title: '提示', content: '请先授权登陆', showCancel: false })
      }
    }
  },

  onPullDownRefresh() {
    this.getPosts().finally(() => {
      wx.stopPullDownRefresh()
      wx.hideLoading()
    })
    console.log('更新')
  }
}
</script>

<template>
  <div class="community-page">
    <article-swiper />
    <div class="ready-publish" @click="handleClick">
      <img class="camera-icon" :src="cameraIco">
    </div>
  </div>
</template>

<style lang="scss">
@import './styles.scss';
</style>

